var parentID;
var searchInput;
var kind;
$(function(){
	parentID=$("#parentID").val();
	$('#goodsTypeTable').datagrid({
		fit:true,
		url:js+'dict/getTreeNodeTabelGoodsType.action?goodsTypeID='+parentID,
		idField:'goodsTypeID',
		fitColumns: true,
		height: 'auto',
		columns:[[{field:'ck',checkbox:true},
               {field:'goodsTypeName',title:'名称',width:80,sortable:true},
			   {field:'goodsTypeCode',title:'编号',width:120,sortable:true}
		]],
		pagination:true,
		rownumbers:true,
		onDblClickRow:function(rowIndex, rowData){
			window.parent.update(rowData);
		}
   });
   
   
   
})
function reloadTable(){
	parentID=$("#parentID").val();
	searchInput = $("#searchInput").val();
	$('#goodsTypeTable').datagrid({
	 	url:js+'dict/getTreeNodeTabelGoodsType.action?goodsTypeID='+parentID+"&searchInput="+searchInput,
    });
   $('#goodsTypeTable').datagrid('reload');
}

function mulDelete(){
	var rows = $('#goodsTypeTable').datagrid('getSelections');
	if(rows.length==0){
		 $.messager.alert('提示',"请选中要删除的纪录","warming");
		 return;	
	}
	$.messager.confirm("提示！","确定要删除选中的货物类型?",function(t){ 
			if(!t) return;
		var goodsTypeIDArray = new Array();
		for(var i=0;i<rows.length>0;i++){
			goodsTypeIDArray.push(rows[i].goodsTypeID);
		}
		var goodsTypeIDsStr = goodsTypeIDArray.join(",");
		$.post(js+"dict/mulDeleteGoodsType.action",{ids:goodsTypeIDsStr},function(result){
		     if(result.success){
		     		while(rows&&rows.length>0){
						var index = $('#goodsTypeTable').datagrid('getRowIndex', rows[0]);
						window.parent.removeTreeNode(rows[0].goodsTypeID);
						$('#goodsTypeTable').datagrid('deleteRow', index);
						rows = $('#goodsTypeTable').datagrid('getSelections');
					}
					return true;
		      }else{
		          $.messager.alert('提示',"删除不成功","error");	
		          return false;
		      }
		},"json");
	});
	
}